#include <graphics.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#define PI 3.14159265358979323846
using namespace std;


void draw_gradient_circle(int cx, int cy, int radius, int width, int length) 
{
	int centerX = cx;
	int centerY = cy;
	const float scale = radius / 200.0f; // 添加比例因子
	radius = (int)(190.0f * scale); 
	
	for (int y = 0; y < length; y++) 
	{
		for (int x = 0; x < width; x++) 
		{
			float dx = x - centerX;
			float dy = y - centerY;
			float dist = sqrt(dx*dx + dy*dy);  // 点到圆心的径向距离
			if (dist > radius) continue;       // 点在圆外，跳过			
			float t = dist / radius;           // 渐变比例（0=中心，1=边缘）
			t = pow(t, 3);                   // 非线性渐变，边缘变黑加速			
			color_t currentColor;
			if (y <= length/2) 
			{  // 上半部分：天蓝色 + 四周变黑
				// 蓝色基础色：RGB(63, 83, 130)
				int r = (int)(80 * (1 - t));
				int g = (int)(100 * (1 - t));  // 绿色通道随距离增加而减少
				int b = (int)(160 * (1 - t));  // 蓝色通道随距离增加而减少
				currentColor = EGERGB(r, g, b);   // 边缘混合黑色（g和b减少）
			} 
			else 
			{  // 下半部分：棕色 + 四周变黑
				// 棕色基础色：RGB(85, 78, 54)
				int r = (int)(110 * (1 - t));
				int g = (int)(101 * (1 - t));// 绿色通道随距离增加而减少
				int b = (int)(70 * (1 - t));
				currentColor = EGERGB(r, g, b);   //边缘变深（g减少）
			}			
			putpixel(x, y, currentColor);
		}
	}	
}

// 双色椭圆结构体
typedef struct 
{
	float x, y;         // 中心坐标
	float a, b;         // 长/短半轴
	float angle;        // 旋转弧度
	color_t top_color;        // 上半部颜色
	color_t bottom_color;     // 下半部颜色
} MyEllipse;


// 初始化椭圆
void initEllipse(MyEllipse* e, float x, float y, float r) 
{
	e->x = x;
	e->y = y;
	e->a = r*0.84;
	e->b = r*0.58;
	e->angle = 0;	
	e->top_color = EGERGB(75,95,155);
	e->bottom_color = EGERGB(105, 95, 65);
}


// 绘制并填充旋转椭圆（上下不同色）
void drawEllipse(const MyEllipse* e, int width, int length,int x,int y, int radius) 
{
	// 核心修改：添加比例计算（基于原始radius=200）
	const float scale = radius / 200.0f;
	
	// 创建临时图像（保持原逻辑）
	const int imgWidth = width;
	const int imgHeight = length;
	
	
	PIMAGE pimg = newimage(imgWidth, imgHeight);
	settarget(pimg);
	setbkcolor(TRANSPARENT);
	cleardevice();
	
	// 中心坐标保持原逻辑
	const float centerX = imgWidth / 2.0f;
	const float centerY = imgHeight / 2.0f;
	
	
	setfillcolor(e->top_color);
	ege_fillpie(centerX - e->a, centerY - e->b, e->a*2, e->b*2, 180, 180, pimg);
	setfillcolor(e->bottom_color);
	ege_fillpie(centerX - e->a, centerY - e->b, e->a*2, e->b*2, 0, 180, pimg);
	
	
	// 中央水平线（线宽参数化）
	setlinestyle(SOLID_LINE, 0, radius*0.02*scale);
	ege_line(centerX - e->a, centerY, centerX + e->a, centerY);
	
	// 俯仰角指示
	setlinestyle(SOLID_LINE, 0, radius*0.01*scale);
	
	// 上方横线（所有数值添加scale系数）
	const float upperY = centerY - radius*0.15*scale;
	ege_line(centerX - radius*0.175*scale, upperY, 
		centerX + radius*0.175*scale, upperY);
	
	// 文字标注（位置和字体参数化）
	LOGFONTW lf;
	ZeroMemory(&lf, sizeof(LOGFONTW));
	lf.lfHeight = 18 * scale;  // 原文字高度18像素参数化
	lstrcpyW(lf.lfFaceName, L"Arial");
	setfont(&lf);
	
	ege_outtextxy(centerX - radius*0.28*scale, upperY - radius*0.055*scale, "10");
	ege_outtextxy(centerX + radius*0.18*scale, upperY - radius*0.055*scale, "10");
	
	// 长横线（第二层）
	const float upperLongY = centerY - radius*0.3*scale;
	ege_line(centerX - radius*0.25*scale, upperLongY, 
		centerX + radius*0.25*scale, upperLongY);
	ege_outtextxy(centerX - radius*0.35*scale, upperLongY - radius*0.05*scale, "20");
	ege_outtextxy(centerX + radius*0.27*scale, upperLongY - radius*0.05*scale, "20");
	
	// 中间短线
	setlinestyle(SOLID_LINE, 0, radius*0.005*scale);
	ege_line(centerX - radius*0.075*scale, centerY - radius*0.075*scale, 
		centerX + radius*0.075*scale, centerY - radius*0.075*scale);
	ege_line(centerX - radius*0.075*scale, centerY - 45*scale, 
		centerX + 15*scale, centerY - 45*scale);
	ege_line(centerX - radius*0.075*scale, centerY - 75*scale, 
		centerX + 15*scale, centerY - 75*scale);
	
	// 下方横线
	setcolor(WHITE);
	setlinestyle(SOLID_LINE, 0, 2*scale);
	ege_line(centerX - 35*scale, centerY + 30*scale, 
		centerX + 35*scale, centerY + 30*scale);
	ege_outtextxy(centerX - 56*scale, centerY + 19*scale, "10");
	ege_outtextxy(centerX + 37*scale, centerY + 19*scale, "10");
	ege_line(centerX - 50*scale, centerY + 60*scale, 
		centerX + 50*scale, centerY + 60*scale);
	ege_outtextxy(centerX - 70*scale, centerY + 50*scale, "20");
	ege_outtextxy(centerX + 51*scale, centerY + 50*scale, "20");
	
	// 下方短线
	setlinestyle(SOLID_LINE, 0, 1*scale);
	ege_line(centerX - 15*scale, centerY + 15*scale, 
		centerX + 15*scale, centerY + 15*scale);
	ege_line(centerX - 15*scale, centerY + 45*scale, 
		centerX + 15*scale, centerY + 45*scale);
	
	// 螺丝参数化（所有位置和尺寸添加scale）
	setcolor(BLACK);
	setlinestyle(SOLID_LINE, 0, 2*scale);
	setfillcolor(EGERGB(65,65,65));
	const float screwSize = 14*scale;
	const float screwX = 155*scale;  // 原155像素偏移
	
	// 左上螺丝
	ege_fillellipse(centerX - screwX, centerY + 5*scale, screwSize, screwSize);
	ege_line(centerX - screwX + 4*scale, centerY + 15*scale, 
		centerX - screwX + 10*scale, centerY + 9*scale);
	
	// 左下螺丝
	ege_fillellipse(centerX - screwX, centerY - 19*scale, screwSize, screwSize);
	ege_line(centerX - screwX + 4*scale, centerY - 9*scale, 
		centerX - screwX + 10*scale, centerY - 15*scale);
	
	// 右侧螺丝（同理）
	ege_fillellipse(centerX + screwX - screwSize, centerY + 5*scale, screwSize, screwSize);
	ege_line(centerX + screwX - 4*scale, centerY + 9*scale, 
		centerX + screwX - 10*scale, centerY + 15*scale);
	
	ege_fillellipse(centerX + screwX - screwSize, centerY - 19*scale, screwSize, screwSize);
	ege_line(centerX + screwX - 4*scale, centerY - 15*scale, 
		centerX + screwX - 10*scale, centerY - 9*scale);
	
	// 保持原有旋转逻辑
	settarget(NULL);
	putimage_rotatezoom(
		NULL, pimg, e->x, e->y, 
		0.5f, 0.5f, e->angle, 1.0f, true, -1, true
		);
	delimage(pimg);
	
}

void drawScale(float cx, float cy, float radius, float angle, int width, int length)
{
	// 核心修改：添加比例因子（基于原始radius=200）
	const float scale = radius / 200.0f;
	
	// 创建临时图像（尺寸自动适配）
	const int imgWidth = width;
	const int imgHeight = length;
	PIMAGE pimg = newimage(imgWidth, imgHeight);
	
	settarget(pimg);    
	setbkcolor(TRANSPARENT);
	cleardevice();
	
	// 图像中心坐标（基于输入参数动态计算）
	const float centerX = imgWidth / 2.0f;
	const float centerY = imgHeight / 2.0f;
	
	// 圆环参数化 ==================================================
	float outerRadius = 190.0f * scale; // 外环半径（原0.95比例）
	float innerRadius = 160.0f * scale;  // 内环半径（原0.8比例）
	
	// 绘制双色圆环
	for (int iy = 0; iy < imgHeight; iy++) 
	{
		for (int ix = 0; ix < imgWidth; ix++) 
		{
			float dx = ix - centerX;
			float dy = iy - centerY;
			float dist = sqrt(dx*dx + dy*dy);
			
			// 跳过非圆环区域
			if (dist <= innerRadius || dist > outerRadius) continue;
			
			// 颜色分布参数化
			color_t currentColor;
			if (iy <= centerY) 
				currentColor = EGERGB(70, 95, 145);  // 上半部蓝色
			else               
				currentColor = EGERGB(115, 105, 73); // 下半部棕色
			
			putpixel(ix, iy, currentColor);
		}
	}
	
	// 刻度参数化 =================================================
	// 主刻度（每30度一个）
	setcolor(WHITE);
	for(int i = 0; i < 7; ++i) // 保持原7个主刻度
	{
		float currentAngle = i * PI / 6.0f; // 30度间隔 (PI/6)
		
		// 仅绘制可见部分（210度范围）
		if(sin(currentAngle) >= -0.4147f) // 对应210度边界条件
		{
			// 刻度线参数化
			float startRadius = innerRadius;
			float endRadius = innerRadius + radius * 0.15f; // 刻度长度占15%半径
			
			int x1 = centerX + startRadius * cos(currentAngle);
			int y1 = centerY - startRadius * sin(currentAngle);
			int x2 = centerX + endRadius * cos(currentAngle);
			int y2 = centerY - endRadius * sin(currentAngle);
			
			// 线宽参数化（主刻度更粗）
			setlinestyle(SOLID_LINE, 0, radius * 0.025f * scale); 
			ege_line(x1, y1, x2, y2);
		}
	}
	
	// 次刻度（每10度一个）
	float startAngle = 70 * PI / 180.0f; // 起始角度70度
	for(int i = 0; i < 5; ++i) // 保持原5组次刻度
	{
		float currentAngle = startAngle + i * PI / 18.0f; // 10度间隔 (PI/18)
		
		if(sin(currentAngle) >= -0.4147f) 
		{
			// 刻度线参数化（更短）
			float startRadius = innerRadius;
			float endRadius = innerRadius + radius * 0.1f; 
			
			int x1 = centerX + startRadius * cos(currentAngle);
			int y1 = centerY - startRadius * sin(currentAngle);
			int x2 = centerX + endRadius * cos(currentAngle);
			int y2 = centerY - endRadius * sin(currentAngle);
			
			// 线宽参数化（次刻度较细）
			setlinestyle(SOLID_LINE, 0, radius * 0.018f * scale);
			ege_line(x1, y1, x2, y2);
		}                    
	}
	
	// 旋转绘制 ===================================================
	settarget(NULL);
	putimage_rotatezoom(
		NULL,           // 目标：主屏幕
		pimg,           // 源图像
		cx,cy, 
		0.5,0.5,     // 旋转中心（图像中心）
		angle,          // 旋转角度（弧度）
		1.0f,           // 缩放比例
		true,           // 透明混合
		-1,             // 不修改透明度
		true            // 抗锯齿
		);
	delimage(pimg);
}


// 精准填充圆角矩形与内切圆之间的区域
// x, y         : 圆角矩形中心坐标
// rectW, rectH : 矩形宽高
// holeRadius   : 中心圆孔的半径
// cornerRadius : 圆角半径
void fill_gray_round_annulus(int x, int y, int rectW, int rectH, int holeRadius, int cornerRadius, int colort)
{
	
	const int GRADIENT_WIDTH = 15; // 渐变区域宽度
	
	// 计算矩形边界
	int left = x - rectW / 2;
	int right = x + rectW / 2;
	int top = y - rectH / 2;
	int bottom = y + rectH / 2;
	
	// 限制圆孔尺寸
	int maxHole = min(rectW, rectH) / 2;
	holeRadius = min(holeRadius, maxHole - GRADIENT_WIDTH);
	
	// 预计算圆角区域参数
	int cr = cornerRadius;
	int innerLeft = left + cr;
	int innerRight = right - cr;
	int innerTop = top + cr;
	int innerBottom = bottom - cr;
	
	for (int py = top; py <= bottom; py++) 
	{
		for (int px = left; px <= right; px++) 
		{
			// 1. 判断是否在圆角矩形内
			bool isInside = false;
			
			// 检查中心矩形区域
			if (px >= innerLeft && px <= innerRight && py >= innerTop && py <= innerBottom) {
				isInside = true;
			}
			// 检查四个圆角区域
			else 
			{
				// 左上角
				if (px <= innerLeft && py <= innerTop) 
				{
					int dx = px - (left + cr);
					int dy = py - (top + cr);
					if (dx * dx + dy * dy <= cr * cr) isInside = true;
				}
				// 右上角
				else if (px >= innerRight && py <= innerTop) 
				{
					int dx = px - (right - cr);
					int dy = py - (top + cr);
					if (dx * dx + dy * dy <= cr * cr) isInside = true;
				}
				// 左下角
				else if (px <= innerLeft && py >= innerBottom) 
				{
					int dx = px - (left + cr);
					int dy = py - (bottom - cr);
					if (dx * dx + dy * dy <= cr * cr) isInside = true;
				}
				// 右下角
				else if (px >= innerRight && py >= innerBottom) 
				{
					int dx = px - (right - cr);
					int dy = py - (bottom - cr);
					if (dx * dx + dy * dy <= cr * cr) isInside = true;
				}
				// 检查四条边区域
				else if ((px >= innerLeft && px <= innerRight) || 
					(py >= innerTop && py <= innerBottom))
				{
					isInside = true;
				}
			}
			
			if (!isInside) continue;
			
			// 2. 计算到圆心的距离
			float dx = px - x;
			float dy = py - y;
			float dist = sqrt(dx * dx + dy * dy);
			
			// 3. 判断是否在圆外
			if (dist > holeRadius) 
			{
				// 计算到圆边的距离
				float edgeDist = dist - holeRadius;
				
				// 渐变强度（0-1，0为渐变最深处）
				float t = edgeDist / GRADIENT_WIDTH;
				t = fmax(0.0f, fmin(t, 1.0f)); // 限制在[0,1]
				
				// 渐变曲线（二次缓动）
				t = t * t * (3 - 2 * t);
				
				// 颜色混合（70→0灰度渐变）
				int gray = colort - (int)(colort * (1 - t));
				putpixel(px, py, EGERGB(gray, gray, gray));
			}
			// 圆内区域保持原背景色（不填充）
		}
	}
}

// 画外部框（参数化版本）
void drawDashboardSurround(float x, float y, float r)
{
	// 核心修改：添加比例计算（基于原始r=200的布局）
	const float scale = r / 200.0f;
	
	// 灰色底座矩形（所有尺寸参数化）
//	setfillcolor(EGERGB(50,50,50));
//	ege_fillroundrect(
//		x - r - 30*scale,    // x坐标
//		y - r - 31*scale,    // y坐标
//		2*r + 62*scale,      // 宽度（原2r+62）
//		2*r + 62*scale,       // 高度
//		10*scale             // 圆角半径
//		);
	
	fill_gray_round_annulus(x+ 3*scale,y+ 2*scale,(462/200.0f)*r,(463/200.0f)*r,(187/200.0f)*r,12,50);	
	
	// 白色上层矩形（尺寸参数化）
//	setfillcolor(WHITE);
//	ege_fillroundrect(
//		x - r - 29*scale, 
//		y - r - 30*scale,
//		2*r + 50*scale,      // 原r*2+50
//		2*r + 3*scale,       // 原2r+3
//		10*scale
//		);
	
	fill_gray_round_annulus(x,y- 2*scale,(453/200.0f)*r,(456/200.0f)*r,(187/200.0f)*r,12,255);	
	
	// 左侧白色装饰条
//	ege_fillroundrect(
//		x - r - 31*scale,
//		y - r - 29*scale,
//		20*scale,            // 原20宽
//		40*scale,            // 原40高
//		10*scale
//		);
	
	fill_gray_round_annulus(x- 1*scale,y,(454/200.0f)*r,(454/200.0f)*r,(187/200.0f)*r,12,255);
	
	// 灰色中层矩形
//	setfillcolor(EGERGB(70,70,70));
//	ege_fillroundrect(
//		x - r - 30*scale,
//		y - r - 29*scale,
//		2*r + 55*scale,     // 原2r+55
//		2*r + 56*scale,      // 原2r+56
//		10*scale
//		);
	
//	fill_gray_annulus(x,y,(445/200.0f)*r,(445/200.0f)*r,(187/200.0f)*r);
	fill_gray_round_annulus(x+ 1*scale,y+ 1*scale,(455/200.0f)*r,(456/200.0f)*r,(187/200.0f)*r,12,70);
	// 外围白色装饰线（线宽参数化）
	setlinestyle(SOLID_LINE, 0, 6*scale);
	setcolor(WHITE);
	
	// 绘制四个圆弧（位置和半径参数化）
	const float arcOffset = 200*scale;  // 原200像素偏移
	
	//下方圆弧（65°-115°）
	for (float i = r + 220*scale; i < r + 223*scale; i += 1.0f) {
		ege_arc(x -i+1.75*scale, y - arcOffset - 422.7*scale, 2 * i, 2 * i, 65.0, 50.35);
	}
	
	// 上方圆弧（245°-295°）
	for (float i = r + 220*scale; i < r + 223*scale; i += 1.0f) {
		ege_arc(x-i, y - arcOffset-20*scale,2*i,2*i ,244.5,50.0);
	}
	
	// 右侧圆弧（334°-386°）
	for (float i = r + 220*scale; i < r + 223*scale; i += 1.0f) {
		ege_arc(x - arcOffset- 4*scale-i, y-i+1.45*scale,2*i,2*i, 334.0, 51);
	}
	
	// 左侧圆弧（154°-206°）
	for (float i = r + 220*scale; i < r + 223*scale; i += 1.0f) {
		ege_arc(x + arcOffset-i+1.1*scale, y-i+2*scale,2*i,2*i ,154.5, 51.5);
	}
}


// 绘制仪表盘指示函数
void drawPointer(int centerX, int centerY, int radius) 
{
	int width = radius/10;  // 指针宽度	
	// 指针头部，绘制一个三角形
	setcolor(WHITE);
	setfillcolor(WHITE);
	int Points[] = {centerX, centerY- radius + radius*0.21, centerX - width / 2, centerY - radius +radius*0.285, centerX + width / 2, centerY - radius + radius*0.285, centerX, centerY - radius + radius*0.21};
	fillpoly(4, Points);
}

void drawDetails(float x, float y, float radius)
{
	// 核心修改：添加比例因子
	const float scale = radius / 200.0f;
	
	// 侧边基准线参数化----------------------------------------------
	setlinestyle(SOLID_LINE, 0, 3*scale);
	setcolor(EGERGB(240,150,50));
	const float sideLineX = x - radius + 95*scale;
	ege_line(sideLineX, y - 70*scale, 
		sideLineX, y + 70*scale);
	
	
	ege_path* path=ege_path_create();
	
	ege_path_addarc(path,x-70*scale,y+70*scale,140*scale,30*scale,178,184);
	ege_path_addline(path,x-31*scale+radius/2,y+83*scale,x+20*scale+radius/2,y+110*scale);
	ege_path_addline(path,x+20*scale+radius/2,y+110*scale,x-20*scale-radius/2,y+110*scale);
	ege_path_addline(path,x-20*scale-radius/2,y+110*scale,x+30*scale-radius/2,y+83*scale);
	setfillcolor(EGERGB(25,25,25));
	ege_fillpath(path);
	ege_path_start(path);
	ege_path_addline(path,x+20*scale+radius/2,y+110*scale,x+radius/3,y+140*scale);
	ege_path_addline(path,x+radius/3,y+140*scale,x-radius/3,y+140*scale);
	ege_path_addline(path,x-radius/3,y+140*scale,x-20*scale-radius/2,y+110*scale);
	setfillcolor(EGERGB(25,25,25));
	ege_fillpath(path);
	
	ege_path *path1=ege_path_create();
	
	ege_path_addline(path1,x-(radius-20*scale)*0.97,y+(80*scale)*0.97,x-radius/3,y+130*scale);
	ege_path_addline(path1,x-radius/3,y+130*scale,x+radius/3,y+130*scale);
	ege_path_addline(path1,x+radius/3,y+130*scale,x+(radius-20*scale)*0.98,y+(80*scale)*0.98);
	ege_path_addarc(path1,x-191*scale,y-190*scale,386*scale,386*scale,30,120);
	setfillcolor(EGERGB(70,70,70));	
	ege_fillpath(path1);
	
	
	// 底部文字参数化----------------------------------------------
	setcolor(WHITE);
	LOGFONTW lf;
	ZeroMemory(&lf, sizeof(LOGFONTW));
	lf.lfHeight = 25 * scale;  // 字体高度参数化
	lf.lfWeight = FW_BOLD;
	lf.lfItalic = TRUE;
	lstrcpyW(lf.lfFaceName, L"微软雅黑");
	setfont(&lf);
	
	// 文字位置参数化
	const float textX = x - 60 * scale;
	const float textY = y + radius - 55*scale;
	ege_outtextxy(textX, textY, "BENDIXIKING");
	
	// 指针绘制（保持已参数化的drawPointer调用）
	drawPointer(x, y, radius);
}


void drawModePlane(float x, float y, float r)
{
	// 核心修改：添加比例因子
	const float scale = r / 200.0f;
	
	// 橙色水平线参数化
	setlinestyle(SOLID_LINE, 0, 4*scale);
	setcolor(EGERGB(240,150,50));
	
	// 线段长度参数化（原90像素）
	const float lineLength = 90.0f * scale;
	ege_line(x - lineLength, y, 
		x - 30.0f*scale, y);
	ege_line(x + 30.0f*scale, y, 
		x + lineLength, y);
	
	// 中心圆点参数化
	setfillcolor(EGERGB(240,150,50));
	const float dotSize = 8.0f * scale;
	ege_fillellipse(x - dotSize/2, y - dotSize/2, 
		dotSize, dotSize);
	
	// 杆子参数化
	setlinestyle(SOLID_LINE, 0, 8*scale);
	setcolor(EGERGB(87,79,53));
	const float poleBottom = y + 70.0f*scale;
	const float poleTop = y + 20.0f*scale;
	ege_line(x, poleBottom, 
		x, poleTop);
	
	// 顶部细线参数化
	setlinestyle(SOLID_LINE, 0, 3*scale);
	ege_line(x, poleTop, 
		x, y + 5.0f*scale);
	
	// 顶部弧线参数化
	const float arcX = x - 30.0f*scale;
	const float arcY = y - 20.0f*scale;
	ege_arc(arcX, arcY, 
		60.0f*scale,   // 原宽度60
		40.0f*scale,   // 原高度40
		0, 180.0);
}

// 绘制仪表盘
void drawDashboard(float x, float y, float radius) 
{
	//绘制一些细节
	drawDetails(x,y,radius);
	//绘制反映飞机俯仰角的小模型
	drawModePlane(x,y,radius);	
}

void drawAttitudeBoard(float centerX, float centerY, float radius, int width, int length, MyEllipse* ellipse)
{
	//绘制外部背景

	draw_gradient_circle(centerX,centerY,radius,width,length);
	// 绘制双色椭圆
	drawEllipse(ellipse,width,length,centerX,centerY,radius);
	drawDashboardSurround(centerX,centerY,radius);
	// 绘制刻度
	drawScale(centerX, centerY, radius, ellipse->angle,width,length);
	drawDashboard(centerX, centerY, radius);
}

int main() 
{
	// 初始化图形窗口
	int width = 800, length = 600;
	initgraph(width, length);
	ege_enable_aa(true);
	//仪表背景色
	setrendermode(RENDER_MANUAL);
	setbkcolor(EGERGB(180,180,180));
	cleardevice();
	float centerX = 400;
	float centerY = 300;
	float radius = 150;
	MyEllipse ellipse;
	initEllipse(&ellipse, centerX, centerY, radius);
	const float move_step = 3.0f;
	const float rotate_step = 0.02f;
	// 绘制仪表盘
	while (!GetAsyncKeyState(VK_ESCAPE)) 
//	while (!kbhit()) 
	{
		// 清屏
		cleardevice();
		if (GetAsyncKeyState(VK_LEFT) & 0x8000) ellipse.x -= move_step;
		if (GetAsyncKeyState(VK_RIGHT) & 0x8000) ellipse.x += move_step;
		if (GetAsyncKeyState(VK_UP) & 0x8000) ellipse.y -= move_step;
		if (GetAsyncKeyState(VK_DOWN) & 0x8000) ellipse.y += move_step;
		if (GetAsyncKeyState('A') & 0x8000) ellipse.angle -= rotate_step;
		if (GetAsyncKeyState('D') & 0x8000) ellipse.angle += rotate_step;
		
		// 角度归一化
		if (ellipse.angle < 0) ellipse.angle += 2 * PI;
		if (ellipse.angle > 2 * PI) ellipse.angle -= 2 * PI;		
		drawAttitudeBoard(centerX,centerY,radius,width,length,&ellipse);
		//更新角度
//		ellipse.angle += rotate_step;
		// 延迟一段时间，控制转动速度
		delay_ms(50);
	}
	getch();
	closegraph();
	return 0;
}